{include file='../library/header.lbi'}
<div class="layui-fluid">
	<div class="layui-card">
		<div class="layui-card-body" style="padding: 15px;">
			<form class="layui-form fn-mt-20" action="">
				<div class="layui-form-item">
					<label class="layui-form-label"><span class="color-red">*</span>帐号</label>
					<div class="layui-input-block">
						<input type="text" name="account" value="{$info.account}" class="layui-input" autocomplete="off" lay-verify="required|account">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">姓名</label>
					<div class="layui-input-block">
						<input type="text" name="name" value="{$info.name}" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">性别</label>
					<div class="layui-input-block">
						<input type="radio" name="sex" value="1" title="男" checked>
						<input type="radio" name="sex" value="2" title="女" {if $info.sex eq 2}checked{/if}>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">手机</label>
					<div class="layui-input-block">
						<input type="text" name="mobile" value="{$info.mobile}" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">邮箱</label>
					<div class="layui-input-block">
						<input type="text" name="email" value="{$info.email}" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">入职时间</label>
					<div class="layui-input-block">
						<input type="text" name="entry_time" value="{if $info.entry_time}{$info.entry_time|date_format:'%Y-%m-%d'}{/if}" class="layui-input layui-date">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label"><span class="color-red">*</span>权限组</label>
					<div class="layui-input-block">
						<select name="group_id" lay-search lay-verify="required">
							<option value="">选择权限组</option>
							{foreach from=$groups item=item}
							<option value="{$item.id}" {if $info.group_id eq $item.id}selected{/if}>{$item.name}</option>
							{/foreach}
						</select>
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">工作职责</label>
					<div class="layui-input-block">
						<textarea type="text" name="workdo" class="layui-textarea">{$info.workdo}</textarea>
					</div>
				</div>
				<div class="layui-form-item layui-layout-admin">
					<div class="layui-input-block">
						<div class="layui-footer" style="left: 0;">
							<input type="hidden" name="id" value="{$info.id}">
							<button class="layui-btn" lay-submit lay-filter="formsubmit">立即提交</button>
						</div>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>
<script>
$(document).ready(function() {
	layui.use('form', function() {
		var form = layui.form;
		form.verify({
			account: function(value, item) {
				var error_message = '';
				$.ajax({
					type: "POST",
					url: "/members/form_verify",
					dataType: 'json',
					data: "type=account&value=" + value + "&id={$info.id}",
					async: false,
					success: function(res) {
						if (res.code == 500) {
							error_message = res.data.error_message;
						}
					}
				});
				if (error_message) return error_message;
			},
		});
		form.on('submit(formsubmit)', function(data) {
			data.elem.disabled = true;
			data.elem.innerHTML = '正在提交..';
			$.ajax({
				type: "POST",
				url: "/members/add",
				dataType: 'json',
				data: data.field,
				success: function(res) {
					if (res.code == 200) {
						layer.msg('保存成功', {
							offset: 'auto',
							icon: 1,
							time: 1000
						}, function() {
							parent.location.reload();
							var index = parent.layer.getFrameIndex(window.name);
							parent.layer.close(index)
						});

					} else {
						layer.msg('保存失败');
					}
				},
				error: function() {
					layer.msg('网络异常，请重试！');
				}
			});
			return false;
		});


	});

});
</script>
{include file='../library/footer.lbi'}